package com.niit.user.service.impl;


import com.niit.user.service.UserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;

/**
 * @author yaojianfeng
 * @EnableBinding 定义消息的推送管道,开启绑定功能
 * 异步消息发送实现类
 */
@EnableBinding({Processor.class})
public class UserMessageServiceImpl implements UserMessageService {
    @Autowired
    private Processor processor;


    @Override
    public String send(String msg) {
        boolean sendFlag = processor.output().send(MessageBuilder.withPayload(msg).build());
        if (sendFlag) {
            return "消息发送成功: "+msg;
        }
        return "消息发送失败: " + msg;
    }


}
